//
//  LKWelcViewController.swift
//  新浪微博
//
//  Created by 胡不归是大虾 on 16/9/26.
//  Copyright © 2016年 胡不归是大虾. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage
class LKWelcViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        //更新UI
        setMyUI()
    }
    
    //MARK:更新UI
    private func setMyUI () {
        //设置约束
        view.addSubview(iconImageView)
        view.addSubview(welcomeLabel)
        iconImageView.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-120)
            make.width.height.equalTo(85)
        }
        welcomeLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(iconImageView)
            make.top.equalTo(iconImageView.snp.bottom).offset(20)
        }
        iconImageView.sd_setImage(with: LKUserInforViewModel.sharedUserInfoViewModel.iconUrl)
    }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        startAnimation()
    }
    //MARK:设置动画
    func startAnimation () {
       
        UIView.animate(withDuration: 1.2, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 5, options: [], animations: {
            self.iconImageView.snp.updateConstraints({ (make) in
                make.bottom.equalTo(self.view).offset(-(UIScreen.main.bounds.height - 120 - 85))
            })
            self.view.layoutIfNeeded()
        }) { (_) in
            UIView.animate(withDuration: 0.5, animations: { 
                self.welcomeLabel.alpha = 1
                }, completion: { (_) in
                    NotificationCenter.default.post(name: Notification.Name(KChangeRootVCNot), object: nil)
            })
        }
    }
    //MARK:控件懒加载
    lazy var iconImageView : UIImageView = {
        let imgV = UIImageView (image: #imageLiteral(resourceName: "avatar_default_big"))
        imgV.cornerRadius = 42
        imgV.layer.borderWidth = 1
        imgV.layer.borderColor = UIColor.orange.cgColor
        return imgV
    }()
    lazy var welcomeLabel : UILabel = {
        let welLabel = UILabel(title: "欢迎回来", font: 14, textColor: UIColor.darkGray)
        welLabel.alpha = 0
        return welLabel
    }()
}
